package com.sundablog.controller.systemsetup.permissionsmanage.permissions;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sundablog.pojo.AdminPermission;
import com.sundablog.result.BaseResult;
import com.sundablog.result.LayUiResult;
import com.sundablog.result.ZTreeResult;
import com.sundablog.service.systemsetup.permissionsManage.permissions.PermissionsService;

/**
 * 权限控制器类
 * @ClassName:  PermissionsController   
 * @Description:权限控制器类  
 * @author: 哒哒 
 * @date:   2018年1月30日 下午10:39:28   
 *     
 * @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
 */
@Controller
@RequestMapping("/systemsetup/permissionsmanage/permissions/")
public class PermissionsController {
	
	@Autowired
	private PermissionsService permissionsService;
	
	/**
	 * 权限控制器显示
	 * @Title: showIndex   
	 * @Description: 权限控制器见面显示
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_index")
	@RequestMapping("/index")
	public String showIndex() {
		return "/systemsetup/permissionsmanage/permissions/index";
	}
	
	/**
	 * 权限控制器添加显示
	 * @Title: addIndex   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_addIndex")
	@RequestMapping("/addIndex")
	public String addIndex() {
		
		return "/systemsetup/permissionsmanage/permissions/add";
	}
	
	/**
	 * 添加权限
	 * @Title: addPermissions   
	 * @Description: 添加权限   
	 * @param: @param adminPermission
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_adminPermission")
	@RequestMapping("/adminPermission")
	@ResponseBody
	public BaseResult addPermissions(AdminPermission adminPermission) {
		int i = permissionsService.addPermissions(adminPermission);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.addSuccess);
		} else {
			return BaseResult.build(209, BaseResult.addFail);
		}
	}
	/**
	 * 查询全部权限
	 * @Title: selectPermissions   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_selectPermissions")
	@RequestMapping("/selectPermissions")
	@ResponseBody
	public BaseResult selectPermissions(){
		List<ZTreeResult> list = permissionsService.selectPermissions();
		return BaseResult.build(200, "", list);
	}
	
	/**
	 * 分页查询
	 * @Title: findPagingQuery   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param page
	 * @param: @param limit
	 * @param: @param pid
	 * @param: @return      
	 * @return: LayUiResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_findPagingQuery")
	@RequestMapping("/findPagingQuery")
	@ResponseBody
	public LayUiResult findPagingQuery(@RequestParam(value="page", defaultValue="1") int page,@RequestParam(value="limit", defaultValue="10") int limit,@RequestParam(value="pid", defaultValue="0") int pid) {
		LayUiResult result = permissionsService.findPagingQuery(page, limit, pid);
		
		return result;
	}
	
	/**
	 * 根据ID查询权限
	 * @Title: selectPermissionsById   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param id
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_selectPermissionsById")
	@RequestMapping("/selectPermissionsById")
	@ResponseBody
	public BaseResult selectPermissionsById(int id) {
		AdminPermission permission = permissionsService.selectPermissionsById(id);
		if (permission != null) {
			return BaseResult.build(200, "", permission);
		} else {
			return BaseResult.build(209, BaseResult.selectFail);
		}
	}
	
	/**
	 * 根据ID修改状态
	 * @Title: updataPermissionsByStatus   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param id
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_permissionsByStatus")
	@RequestMapping("/permissionsByStatus")
	@ResponseBody
	public BaseResult updataPermissionsByStatus(int id) {
		int i = permissionsService.updataPermissionsByStatus(id);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(209, BaseResult.updataFail);
		}
		
	}
	/**
	 * 编辑界面显示
	 * @Title: editIndx   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_editIndex")
	@RequestMapping("/editIndex")
	public String editIndx() {
		return "/systemsetup/permissionsmanage/permissions/edit";
	}
	
	/**
	 * 修改权限
	 * @Title: updataPermissions   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param adminPermission
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_updataPermissions")
	@RequestMapping("/updataPermissions")
	@ResponseBody
	public BaseResult updataPermissions(AdminPermission adminPermission) {
		int i = permissionsService.updataPermissions(adminPermission);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(209, BaseResult.updataFail);
		}
	}
	/**
	 * 查看界面显示
	 * @Title: detailIndex   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_permissionsmanage_permissions_detailIndex")
	@RequestMapping("/detailIndex")
	public String detailIndex() {
		return "/systemsetup/permissionsmanage/permissions/detail";
	}
}
